﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisionCloud.Core.Model.Sys;
using VisionCloud.Domain.Repository.Interface.Sys;

namespace VisionCloud.Domain.Repository.Implement.Sys
{
    public class SysUserUpdateRecordRepository : BaseRepository<SysUserUpdateRecord>, ISysUserUpdateRecordRepository
    {
        public SysUserUpdateRecord GetLastRecordForUser(Guid userId)
        {
            return GetAll().Where(x => !x.IsDeleted && x.UserId == userId && x.PublishDate <= DateTime.Now).OrderByDescending(x => x.PublishDate).FirstOrDefault();
        }

        public SysUserUpdateRecord GetRecord(string deviceMac, string version)
        {
            return GetAll().Where(x => !x.IsDeleted && x.DeviceMac == deviceMac && x.DeviceVersion == version).OrderByDescending(x => x.CurrentVersion).FirstOrDefault();
        }
    }
}
